#include "Stdafx.h"
#include "Object3D.h"

namespace Pulpy
{
	bool Object3D::Contain(Object3D & ob)
	{
		if(&ob == this)
		{
			Logger::getInstance().addLog("Object3D::Error checking Contain on self");
			return false;
		}
		if(!ob._Solid || !_Solid)
			return false;
		//Not possible for smaller objects to contain larger ones
		if(ob.getWidth() > _Width || ob.getHeight() > _Height || ob.getDepth() > _Depth)
			return false;
		if(ob._Radius == 0 && ob._Position.getX() - ob._Width / 2.0f <= _Position.getX() - _Width / 2.0f
			&& ob._Position.getX() + ob._Width / 2.0f + ob._Width >= _Position.getX() + _Width / 2.0f
			&& ob._Position.getY() - ob._Height / 2.0f >= _Position.getY() - _Height / 2.0f
			&& ob._Position.getY() + ob._Height / 2.0f <=  _Position.getY() + _Height / 2.0f
			&& ob._Position.getZ() - ob._Depth / 2.0f >= _Position.getZ()  + _Depth / 2.0f
			&& ob._Position.getZ() + ob._Depth / 2.0f <=  _Position.getZ() + _Depth / 2.0f)
			return true;
		//Circle to circle intersect
		if((ob._Position - _Position).getMag()- _Radius + ob._Radius <= 0)
			return true;
		return false;
	}
	bool Object3D::Contain(Vector3D<float> &v)
	{
		if(v.getX() <= _Position.getX() + _Width
			&& v.getX() >= _Position.getX()
			&& v.getY() >= _Position.getY() 
			&& v.getY() <=  _Position.getY() + _Height
			&& v.getZ() >= _Position.getZ() 
			&& v.getZ() <=  _Position.getZ() + _Depth)
			return true;
		return false;
	}
	bool Object3D::Intersects(Object3D &ob)
	{
		if(&ob == this)
		{
			Logger::getInstance().addLog("Object3D::Error checking Intersects on self");
			return false;
		}
		if(Contain(ob))
			return true;
		if(ob._Radius == 0 && ob._Position.getX() <= _Position.getX() + _Width
			&& ob._Position.getX() + ob._Width >= _Position.getX()
			&& ob._Position.getY() + ob._Height >= _Position.getY() 
			&& ob._Position.getY() <=  _Position.getY() + _Height
			&& ob._Position.getZ() + ob._Depth >= _Position.getZ() 
			&& ob._Position.getZ() <=  _Position.getZ() + _Depth)
			return true;
		//Circle to circle intersect
		if((ob._Position - _Position).getMag()- _Radius + ob._Radius <= 0)
			return true;
		return false;
	}
}